package com.kingdee.eas.custom.wg.rpts;

import java.awt.Window;
import java.util.ArrayList;

import org.apache.log4j.Logger;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.ui.face.CoreUIObject;
import com.kingdee.eas.mm.basedata.BOMExtendCondition;
import com.kingdee.eas.mm.basedata.BOMExtendFacadeFactory;
import com.kingdee.eas.mm.basedata.BOMExtendLevelEnum;
import com.kingdee.eas.mm.basedata.BOMSearchFlagEnum;
import com.kingdee.eas.mm.basedata.BOMTypeEnum;
import com.kingdee.eas.mm.basedata.BomFactory;
import com.kingdee.eas.mm.basedata.BomInfo;
import com.kingdee.eas.mm.basedata.BomTreeCondition;
import com.kingdee.eas.rpts.ctrlsqldesign.param.AbstractJavaDataSet;
import com.kingdee.eas.util.SysUtil;
import com.kingdee.eas.util.client.EASResource;
import com.kingdee.eas.util.client.MsgBox;
import com.kingdee.jdbc.rowset.IRowSet;

public class BOMExtend extends AbstractJavaDataSet{
	

	private static final Logger logger;
	
	static 
    {
        logger = CoreUIObject.getLogger(com.kingdee.eas.mm.basedata.client.BomExtendSearchListUI.class);
    }
	public BOMExtend() {
		// TODO Auto-generated constructor stub
		
	}
	@Override
	public IRowSet[] getCustomRowSet(Window parent, String otherDataCenter)
			throws Exception {
		// TODO Auto-generated method stub
		//String BomGroupID=filterParamMap.get("BomGroupID").toString();
		String materialId=filterParamMap.get("materialId").toString();
		String storageOrgUnitID=filterParamMap.get("storageOrgUnitID").toString();
		String bomId=null;
		IRowSet rowSet = null;
		String sql=" where Material = '"+ materialId+"' and BomType=40 and usageType=10";
		BomInfo bom=null;
		try{
			bom= BomFactory.getRemoteInstance().getBomInfo(sql);
		}
		catch(Exception e){

		}
	
		
		if(bom != null) bomId=bom.getId().toString();
		else bomId="bomId is not exist";
//		if(null != bomId)
//		{
			
			BomTreeCondition condition = new BomTreeCondition();
	        condition.setBomID(bomId);
	        condition.setQueryType(BOMSearchFlagEnum.MultilevelSearch);
	        condition.setQueryDate(null);
	        condition.setProjectNumID(null);
	        condition.setTrackNumID(null);
	        condition.setBomtype(BOMTypeEnum.MfgBOM);
            java.util.List returnFieldList = new ArrayList();
            returnFieldList.add("FID");
            returnFieldList.add("FLevel");
            returnFieldList.add("FCHILDMATERIALID");
            returnFieldList.add("FMaterialNumber");
            returnFieldList.add("FMaterialName");
            returnFieldList.add("FMODEL");
            returnFieldList.add("FUnitName");
            returnFieldList.add("FMaterialAttr");
            returnFieldList.add("FBaseQty");
            returnFieldList.add("qtyPrecision");
            returnFieldList.add("FBomId");
            returnFieldList.add("FParentBomId");
            returnFieldList.add("FProportion");
            returnFieldList.add("FParentComsumeQty");
            returnFieldList.add("FScrapRatio");
            returnFieldList.add("FEffectiveDate");
            returnFieldList.add("FDisableDate");
            returnFieldList.add("FOutputType");
            returnFieldList.add("FMaterialChar");
            returnFieldList.add("FIssMode");
            returnFieldList.add("FDefaultWarehouseName");
            returnFieldList.add("Fnumber");
            returnFieldList.add("FBomName");
            returnFieldList.add("FConsumeType");
            String returnFields[] = (String[])returnFieldList.toArray(new String[0]);
            BOMExtendCondition conditionForIntegratedSearch = new BOMExtendCondition();
            conditionForIntegratedSearch.setExtendLevel(BOMExtendLevelEnum.AllLevelExtend);
            conditionForIntegratedSearch.setStorateOrgID(storageOrgUnitID);
            conditionForIntegratedSearch.setGroupByMaterial(false);
            conditionForIntegratedSearch.setOnlyExtendConfig(false);
            conditionForIntegratedSearch.setOnlyExtendVirtual(false);
            conditionForIntegratedSearch.setReturnFields(returnFields);
            conditionForIntegratedSearch.setBomId(bomId);
            conditionForIntegratedSearch.setBomType(BOMTypeEnum.MfgBOM);
            conditionForIntegratedSearch.setProjectNumID(null);
            try
            {
                rowSet = BOMExtendFacadeFactory.getRemoteInstance().getExtendRowSetByMaterialID(materialId, null, conditionForIntegratedSearch);
            }
            catch(BOSException e)
            {
                logger.error(e.getMessage());
                MsgBox.showInfo(EASResource.getString("com.kingdee.eas.mm.basedata.BOMCompareResource", "Info_PleaseCheckBOMData"));
                SysUtil.abort();
            }
            
//		}
		
		return new IRowSet[]{rowSet};
	}
	
	@Override
	public String getCustomSQL(Window parent) throws Exception {
		// TODO Auto-generated method stub
		return super.getCustomSQL(parent);
	}


	

	
}
